package com.djahva.image;

//import org.apache.log4j.Logger;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: geert
 * Date: Jun 13, 2008
 * Time: 8:59:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class HttpImageProvider implements ImageProvider {

    public BufferedImage getImage(ImageRequest imageRequest, String location) throws IOException {
        BufferedImage buff = null;
        if (! location.endsWith("/")){
            location = location + "/";
        }
        try {
            URL url = new URL(location + imageRequest.getImg());
            imageRequest.log("Read Image from url "+url);
            buff = ImageIO.read(url);
        } catch (MalformedURLException e) {
            //Logger.getLogger(this.getClass()).error("Error", e);
        }        
        return buff;
    }
}

